import {
	mapGetters

} from "vuex";
import storage from "./storage";
import {
	getMyShareInfo
} from "@/api/game.js"

export default {
	data() {
		return {}
	},
	computed: {
		...mapGetters(["globalGameCtx"]),
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage(resultData) {
		const promise = new Promise((resolve, reject) => {
			getMyShareInfo({
				gameId: this.globalGameCtx.gameId
			}).then(res => {
				console.log("分享请求成功", res);
				let {
					photoUrl,
					shareCode,
					title
				} = res.data.result
				let shareTitle = !title ? storage.getGameDetail().gameName : title
				let shareImage = !photoUrl ? storage.getGameDetail().gamePhoto : photoUrl
				let gameId = !this.globalGameCtx.gameId ? "" : this.globalGameCtx.gameId
				let sharePath = `pages/game/play/index?goodsId=${gameId}&shareCode=${shareCode}`

				if (resultData.from == "menu") {
					resolve({
						title: shareTitle,
						imageUrl: shareImage,
						path: sharePath,
					})

				}
				if (resultData.from == "button") {
					resolve({
						title: shareTitle,
						imageUrl: shareImage,
						path: sharePath,
					})
				}

			}).catch(err => {

			})
		})


		// console.log(res, "onShareAppMessage-----------分享给朋友");
		// if (res.from == "menu") {
		// 	return {
		// 		title: storage.getGameDetail().gameName,
		// 		imageUrl: storage.getGameDetail().gamePhoto,
		// 		path: `pages/game/play/index?goodsId=${this.globalGameCtx.gameId}`,
		// 	};
		// }
		// if (res.from == "button") {
		// 	return {
		// 		title: storage.getGameDetail().gameName,
		// 		imageUrl: storage.getGameDetail().gamePhoto,
		// 		path: `pages/game/play/index?goodsId=${this.globalGameCtx.gameId}`,
		// 	};
		// }

		return {
			promise
		}

	},
	// 分享到朋友圈
	onShareTimeline(res) {
		console.log(res, "onShareAppMessage-----------分享到朋友圈");
		return {
			title: "逃出疯人院",
			imageUrl: "https://cdn.osisx.com/game/image/247337192468455cb28be754a09f116f.png",
			path: `pages/game/play/index?goodsId=${this.globalGameCtx.gameId}`,
		}
	},
}